<%@ page language="java" import="com.qipay.admin.tags.PageModel" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.admin.utils.SiteHelper" %>
<%@ page import="com.qipay.baas.model.CpChannel" %>
<%@ page import="com.qipay.baas.model.CpInfo" %>
<%@ page import="com.qipay.baas.model.User" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<!doctype html>
<html>
<head>
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <script type="text/javascript">
        //document.getElementsByTagName("html")[0].style.width=screen.availWidth/100+"px";
        document.getElementsByTagName("html")[0].style.fontSize=screen.availWidth/200+"px";
    </script>
    <style type="text/css">
        .border{
            border:1px solid red;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <% CpInfo cpInfo = (CpInfo) request.getAttribute("detail");
            Byte cpType= (Byte)request.getAttribute("cpType");
            User currentUser = (User) session.getAttribute("user");
            UserLevel userLevel = SiteHelper.getUserLevelByLevel(currentUser.getLevel());
        %>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title"><%= cpInfo.getName()%>，拥有的支付方式列表</h3>
                        </div>
                        <div class="button-group">
                                <button type="button" class="button back-white" onclick="window.history.back()" style="font-size: 1rem">返回
                                </button>
                                <% if(userLevel==UserLevel.ADMIN || (userLevel==UserLevel.AGENT&&cpType==1)){%>
                                <a href="${pageContext.request.contextPath}/cp/channel/add?cpid=<%= cpInfo.getCpId()%>">
                                    <button type="button" class="button back-green" style="font-size: 1rem">【添加支付方式】</button></a>
                                <%}%>
                        </div>
                        <hr>
                        <!-- /.box-header -->
                        <div class="tableContent" style="font-size: 12px">
                            <table width="100%" cellspacing="0" cellpadding="0" border="1">
                                <thead>
                                <tr>
                                    <th width="5%">ID</th>
                                    <th width="5%">支付方式</th>
                                    <th width="8%">费率(%)</th>
                                    <th width="8%">垫支比(%)</th>
                                    <th width="5%">状态</th>
                                    <th width="5%">更新时间</th>
                                    <th width="10%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<CpChannel> articles = (List<CpChannel>) request.getAttribute("lst");
                                    PageModel pager = (PageModel) request.getAttribute("page");
                                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                                    if (articles != null && articles.size() > 0) {
                                        Iterator<CpChannel> iter = articles.iterator();
                                        CpChannel user = null;
                                        while (iter.hasNext()) {
                                            user = iter.next();
                                %>
                                <tr id="user_<%=user.getId()%>">
                                    <td><%=user.getCpId()%>
                                    </td>
                                    <td><%=SiteHelper.getChannelTypeString(user.getChannelType())%>
                                    </td>
                                    <td><%=user.getFeeRecharge().multiply(SiteHelper.decimalFor100)%>
                                    </td>
                                    <td><%=user.getRateAdvince().multiply(SiteHelper.decimalFor100)%>
                                    </td>
                                    <td id="trgoods<%= user.getId()%>"
                                        class="<%= user.getState()!=null&&user.getState()==0?"success":""%>"><%= SiteHelper.getChannelStateString(user.getState())%>
                                    </td>
                                    <td>
                                        <%= sdf.format(user.getUpdateDate())%>
                                    </td>
                                    <td>
                                        <% if (userLevel == UserLevel.ADMIN) {%>
                                        <a name="lnkDelete"
                                           s="<%= user.getState()!=null&&user.getState()==0?"200":"100"%>"
                                           pk="<%= user.getId()%>" href="javascript:;">
                                            <button type="button" class="button back-green" style="font-size: 1rem"><%= user.getState() != null && user.getState() == 0 ? "禁用" : "启用"%></button>
                                        </a>

                                        <%}%>
                                        <% if(userLevel==UserLevel.ADMIN || (userLevel==UserLevel.AGENT&&cpType==1)){%>
                                        <a href="${pageContext.request.contextPath}/<%= cpType==2?"proxy":"cp"%>/channel/<%= user.getId()%>">
                                            <button type="button" class="button back-green"  style="font-size: 1rem">修改</button></a>
                                        <a  name="lnkRemove" href="javascript:;" pk="<%= user.getId()%>">
                                            <button type="button" class="button back-green" style="font-size: 1rem">删除</button></a>
                                        <%}%>
                                    </td>
                                </tr>

                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="7">no data.</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.dataTables.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/dataTables.bootstrap.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>
    $(function () {

        $("[name='lnkDelete']").click(function () {
            var that = $(this);
            var pk = $(this).attr("pk");
            var state = $(this).attr("s");
            var isSuccess = state == "200";
            if (confirm(isSuccess ? "确定禁用吗？" : "确定启用吗？")) {
                state = isSuccess ? 1 : 200;
                if (pk > 0) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=setcpchannelstate&id=" + pk + "&id2=" + state,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {
                                if (isSuccess) {
                                    $("#trgoods" + pk).removeClass("success");
                                    $("#trgoods" + pk).html("禁用");
                                    $(this).html("启用");
                                    $(this).attr("s", "100");
                                }
                                else {
                                    $("#trgoods" + pk).addClass("success");
                                    $("#trgoods" + pk).html("启用");
                                    $(this).html("禁用");
                                    $(this).attr("s", "200");
                                }
                            }
                            else {
                                alert("fail:" + data);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }
        });
        $("[name='lnkRemove']").click(function () {
            var pk = $(this).attr("pk");
            if (pk > 0) {
                if (confirm("确定删除吗？")) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=delcpchbyid&id=" + pk,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {
                                $("#user_" + pk).hide(100);
                            }
                            else {
                                alert("fail:" + data);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }

        });
    })
</script>
</body>
</html>

